import {
  Table,
  Row,
  Col,
  Form,
  Input,
  Icon,
  InputNumber,
  Radio,
  DatePicker,
  Select,
  Upload,
  Button,
  Switch,
  Modal,
  Popconfirm,
  Tabs,
  message,
  Steps,
} from 'antd';

import { FormComponentProps } from 'antd/es/form';
import React from 'react';
import SingleDragger from '../../../../../../components/Commons/SingleDragger';
import { connect } from 'dva';
import CurrencySelect from '../utils/CurrencySelect.tsx';
import Constants from '@/utils/Constants';
import BizParams from '../utils/BizParams.tsx';
import moment from 'moment';
const R = require('ramda');
const FormItem = Form.Item;

const SupplygoodAdd = Form.create()(
  class SupplygoodAdd extends React.Component {
    constructor(props) {
      super(props);
      this.state = {
        open: false,
      };
    }


    getForm = () => {
      const {form, dispatch, handleSave, recordFormValues} = this.props;
      let url1 = this.refs.certInfoReceipt.getUrl();
      let url2 = this.refs.certInfoTaxRegister.getUrl();
      let url3 = this.refs.certInfoTaxplayer.getUrl();
      let url4 = this.refs.certInfoBussinessLicense.getUrl();
      let url5 = this.refs.certInfoSaleCheck.getUrl();
      let url6 = this.refs.certInfoVATVoice.getUrl();
      let url7 = this.refs.certInfoProtocal.getUrl();
      let url8 = this.refs.certInfoOther.getUrl();
      let updatetime = null;
      let identifitime = null;
      form.validateFields((err, fieldsValue) => {
        updatetime = moment(fieldsValue['updatetime']).format('YYYY-MM-DD');
        identifitime = moment(fieldsValue['identifitime']).format('YYYY-MM-DD');
        if (err) return;
        const formVals = {...fieldsValue};
        formVals.certInfoReceipt = url1;
        formVals.certInfoTaxRegister = url2;
        formVals.certInfoTaxplayer = url3;
        formVals.certInfoBussinessLicense = url4;
        formVals.certInfoSaleCheck = url5;
        formVals.certInfoVATVoice = url6;
        formVals.certInfoProtocal = url7;
        formVals.certInfoOther = url8;
        handleSave(formVals);
      });

      form.validateFields((errors, values) => {
        if (errors) return;

        values.updatetime = updatetime;
        values.identifitime = identifitime;
        values.certInfoReceipt = url1;
        values.certInfoTaxRegister = url2;
        values.certInfoTaxplayer = url3;
        values.certInfoBussinessLicense = url4;
        values.certInfoSaleCheck = url5;
        values.certInfoVATVoice = url6;
        values.certInfoProtocal = url7;
        values.certInfoOther = url8;
        this.props.dispatch({
          type:  'customsInfoGenerate/createDrawer',
          payload: {
            ...values,
            onSuccess: () => {
              this.handleCancel();
            },
            onFail: () => {
              this.handleCancel();
            },
          },
        });

      });
    };

    getUrl = () => {
      return this.state.dbUrl;
    }


    handleOpen = () => {
      this.setState({ open: true });
    };

    handleCancel = () => {
      const { dispatch } = this.props;
      this.props.form.resetFields();
      if (this.refs.unapprovalfile) this.refs.unapprovalfile.resetUpload();
      dispatch({ type: 'customsInfoGenerate/querySupplygoodList', payload: {} });
      this.setState({ open: false });
    };

    render() {
      // const { getFieldDecorator } = this.props.form;
      const {
        form: {getFieldDecorator, getFieldValue},
        drawersList,
      } = this.props;

      let footer = [];
      footer.push(
        <Button key="cancel" size="large" onClick={this.handleCancel.bind(this)}>
          取消
        </Button>,
      );
      footer.push(
        <Button
          key="submit"
          size="large"
          loading={this.props.loading}
          onClick={() => this.getForm()}
        >
        确认
        </Button>,
      );

      return (
        <Modal
          destroyOnClose
          title="报关抬头新增"
          visible={this.state.open}
          width={1200}
          footer={footer}
          onCancel={this.handleCancel}
        >
          <Form>
              <Row gutter={24}>
                <Col xs={24} md={12}>
                  <FormItem label={<span>开票工厂名称</span>}>
                    {getFieldDecorator('name', {
                      rules: [{required: true, message: '请填写开票工厂名称！'}],
                    })(<Input placeholder="请填写开票工厂名称"/>)}
                  </FormItem>
                </Col>
                <Col xs={24} md={6}>
                  <FormItem label={<span>纳税人识别号</span>}>
                    {getFieldDecorator('taxplayercode', {
                      rules: [{required: true, message: '请填写订纳税人识别号！'}],
                    })(<InputNumber placeholder="请输入纳税人识别号" style={{width: '100%'}}/>)}
                  </FormItem>
                </Col>
                <Col xs={24} md={6}>
                  <FormItem label={<span>一般纳税人认定时间</span>}>
                    {getFieldDecorator('identifitime', {
                      rules: [{required: true, message: '请填写一般纳税人认定时间'}],
                    })(<DatePicker style={{width: '100%'}}/>)}
                  </FormItem>
                </Col>
              </Row>
              <Row gutter={24}>
                <Col xs={24} md={6}>
                  <FormItem label={<span>预计月均出口额（万）</span>}>
                    {getFieldDecorator('exportvolume', {
                      rules: [{required: true, message: '请填写预计月均出口额！'}],
                    })(<InputNumber placeholder="请填写预计月均出口额" style={{width: '100%'}}/>)}
                  </FormItem>
                </Col>

                <Col xs={24} md={6}>
                  <FormItem label={<span>出口额币种</span>}>
                    {getFieldDecorator('exportvolumecurrency', {
                      rules: [{required: true, message: '请选择报关币种！'}],
                    })(<CurrencySelect/>)}
                  </FormItem>
                </Col>

                <Col xs={24} md={6}>
                  <FormItem label={<span>境内货源地</span>}>
                    {getFieldDecorator('supplygoods', {
                      rules: [
                        {
                          required: true,
                          message: '请选择境内货源地！',
                        },
                      ],
                    })(<BizParams sprCode={'supplyGoods'} disabled={false}/>)}
                  </FormItem>
                </Col>
                <Col xs={24} md={6}>
                  <FormItem label={<span>厂房面积</span>}>
                    {getFieldDecorator('workshop', {
                      rules: [{required: true, message: '请填写厂房面积！'}],
                    })(<InputNumber placeholder="请填写厂房面积" style={{width: '100%'}}/>)}
                  </FormItem>
                </Col>
              </Row>
              <Row gutter={24}>
                <Col xs={24} md={12}>
                  <FormItem label={<span>开票工厂地址</span>}>
                    {getFieldDecorator('address', {
                      rules: [{required: true, message: '请填写开票工厂地址！'}],
                    })(<Input placeholder="请填写开票工厂地址"/>)}
                  </FormItem>
                </Col>
                <Col xs={24} md={6}>
                  <FormItem label={<span>员工人数</span>}>
                    {getFieldDecorator('staffnum', {
                      rules: [{required: true, message: '请填写员工人数！'}],

                    })(<InputNumber placeholder="请填写员工人数" style={{width: '100%'}}/>)}
                  </FormItem>
                </Col>
                <Col xs={24} md={6}>
                  <FormItem label={<span>成立日期</span>}>
                    {getFieldDecorator('updatetime', {
                      rules: [{required: true, message: '请填写成立日期'}],

                    })(<DatePicker style={{width: '100%'}}/>)}
                  </FormItem>
                </Col>
              </Row>
              <Row gutter={24}>
                <Col xs={24} md={6}>
                  <FormItem label={<span>联系人</span>}>
                    {getFieldDecorator('contactname', {
                      rules: [{required: true, message: '请填写联系人！'}],
                    })(<Input placeholder="请填写联系人"/>)}
                  </FormItem>
                </Col>
                <Col xs={24} md={6}>
                  <FormItem label={<span>联系电话</span>}>
                    {getFieldDecorator('contacttel', {
                    })(<InputNumber placeholder="请填写联系电话" style={{width: '100%'}}/>)}
                  </FormItem>
                </Col>
                <Col xs={24} md={12}>
                  <FormItem label={<span>备注</span>}>
                    {getFieldDecorator('memo', {
                    })(<Input placeholder="请填写备注"/>)}
                  </FormItem>
                </Col>
              </Row>
              <Row gutter={24}>
                <Col xs={24} md={6}>
                  <FormItem label="销项发票" hasFeedback>
                    <SingleDragger
                      ref="certInfoReceipt"
                      url={''}
                      dataSource={''}
                      module={'drawer'}
                    />
                  </FormItem>
                </Col>
                <Col span={6}>
                  <FormItem label="销项发税务登记证副本" hasFeedback>
                    <SingleDragger
                      ref="certInfoTaxRegister"
                      url={''}
                      dataSource={''}
                      module={'drawer'}
                    />
                  </FormItem>
                </Col>
                <Col span={6}>
                  <FormItem label="一般纳税人认定书" hasFeedback>
                    <SingleDragger
                      ref="certInfoTaxplayer"
                      url={''}
                      dataSource={''}
                      module={'drawer'}
                    />
                  </FormItem>
                </Col>
                <Col span={6}>
                  <FormItem label="营业执照副本" hasFeedback>
                    <SingleDragger
                      ref="certInfoBussinessLicense"
                      url={''}
                      dataSource={''}
                      module={'drawer'}
                    />
                  </FormItem>
                </Col>
              </Row>
              <Row gutter={24}>
                <Col span={6}>
                  <FormItem label="销售验厂情况" hasFeedback>
                    <SingleDragger
                      ref="certInfoSaleCheck"
                      url={''}
                      dataSource={''}
                      module={'drawer'}
                    />
                  </FormItem>
                </Col>
                <Col span={6}>
                  <FormItem label="进项发票" hasFeedback>
                    <SingleDragger
                      ref="certInfoVATVoice"
                      url={''}
                      dataSource={''}
                      module={'drawer'}
                    />
                  </FormItem>
                </Col>
                <Col span={6}>
                  <FormItem label="外贸出口协议" hasFeedback>
                    <SingleDragger
                      ref="certInfoProtocal"
                      url={''}
                      dataSource={''}
                      module={'drawer'}
                    />
                  </FormItem>
                </Col>
                <Col span={6}>
                  <FormItem label="其他" hasFeedback>
                    <SingleDragger
                      ref="certInfoOther"
                      url={''}
                      dataSource={''}
                      module={'drawer'}
                    />
                  </FormItem>
                </Col>
              </Row>
          </Form>
        </Modal>
      );
    }
  },
);

function mapStateToProps(state) {
  return {
    loading: state.loading.models.creditFinance,
  };
}

export default connect(mapStateToProps)(SupplygoodAdd);
